#!/usr/bin/perl -w

use strict;
use lib `fvwm-perllib dir`;
use FVWM::Module;

my $module = new FVWM::Module(Debug => 2);

my @tracker_names = qw(
	Colorsets GlobalConfig ModuleConfig PageInfo Scheduler WindowList
);

foreach my $name (@tracker_names) {
	my %params = ();
	%params = ( ModuleName => $0 ) if $name eq "Scheduler";
	%params = (
		ModuleName => "FvwmIdent",
		DefaultConfig => { Font => 'missing' }
	) if $name eq "ModuleConfig";

	my $tracker = $module->track($name, %params);
	if ($name eq "Scheduler") {
		$tracker->schedule(30, sub {
			my $old_timeout = $_[0]->{seconds};
			my $new_timeout = $old_timeout - 10;
			$module->terminate if $new_timeout <= 0;
			$tracker->reschedule($new_timeout);
		});
	}
	$module->debug(
		"$name: initialized\n" . $tracker->dump . ("-" x 74)
	);
	$tracker->observe("main", sub {
		my ($module, $tracker, $info, @params) = @_;
		my $headline = "$name: " . $tracker->observables->[0];
		$module->debug(
			"$headline\n" . $tracker->dump(@params) . ("-" x 74)
		);
	});
}

$module->event_loop();
